<%--
  Created by IntelliJ IDEA.
  User: EDZ
  Date: 2022/9/29
  Time: 17:19
  To change this template use File | Settings | File Templates.
--%>
<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>
<% String path = request.getContextPath(); request.setCharacterEncoding("UTF-8");
    String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <base href="<%=basePath%>">
    <title>批单对账查询</title>
    <jsp:include page="/WEB-INF/jsp/common/common.jsp"></jsp:include>
    <link href="css/calendar.css"  rel="stylesheet" type="text/css" >
    <link rel="stylesheet" href="<%=path%>/css/zTreeStyle/zTreeStyle.css">
    <script type="text/javascript" src="<%=path%>/js/jquery.ztree.core-3.5.js"></script>
    <script type="text/javascript" src="<%=path%>/js/jquery.ztree.excheck-3.5.js"></script>
    <script src="<%=path%>/js/jquery.divbox.js" type="text/javascript"></script>
    <style type="text/css">
        .sub-title {
            background: none repeat scroll 0 0 #ffffff;
            font-size: 100%;
            font-weight: bold;
            height: 30px;
            line-height: 30px;
            text-indent: 10px;
            width: 100%;
        }
    </style>
    <script language="javascript" type="text/javascript">
        var defaultBranch;//保存默认机构的值
        // 用于存储查询条件
        var zfbMap = {};
        $(document).ready(function() {
            isReadyIframe();
            defaultDate();
        });

        function isReadyIframe(){
            var iframe = $(window.parent.document).find("#iframe").length;
            if(iframe==0){
                window.location.href="<%=basePath%>index.jsp";
            }
        }

        //“重置”查询条件
        function  resetCriteria(){
            $('#downloadlifePolicyFileForm input[type!="button"]').val("");
            $('#downloadlifePolicyFileForm select[name!="privilegeBranch"]').val("");
            $("#privilegeBranch").val(defaultBranch);//机构置为默认机构
        }

        //点击“查询”
        function queryLifePolicy(pageIndex){
            var downloadFlag = false;
            if(pageIndex == null){
                pageIndex = 1;
            }
            if(pageIndex == -1){
                pageIndex = 1;
                downloadFlag = true;
            }

            var asyncFlag = true;
            if(pageIndex == -1){
                asyncFlag = false;
            }

            if (checkConditions()) {
                var jsonDate = checkConditions()
            } else {
                return false
            }

            jsonDate.pageIndex = pageIndex
            $.openLoading();
            $.ajax({
                url : "<%=path%>/zfbController/queryZfbRefundInfo",
                type : 'POST',
                async : asyncFlag,
                dataType:'json',
                data: jsonDate,
                success:function(page){
                    $.closeLoading();
                    if($.validate(page))return;
                    if(page.result == 'noChannelInfo'){
                        //清空表格数据
                        $("#lifePolicyTable").find("tbody").remove();
                        $("#lifePolicyPageDiv").html("");
                        $.message("error", "查询数据为空，请正确填写查询条件和页码。");
                        return;
                    }

                    // 查询数据为空
                    if (page.data.length ===0) {
                        //清空表格数据
                        $("#lifePolicyTable").find("tbody").remove();
                        $("#lifePolicyPageDiv").html("");
                        $.message("error", "查询数据为空，请正确填写查询条件和页码。");
                        return;
                    }
                    zfbMap = page.type;
                    var fieldNames = "policyNo,polno,endorseNo,refoundMoney,validDate,creatTime,beginDate,endDate,bbrName,effTime";
                    var tableContent = creatTable2(fieldNames,page,null,null);
                    var tableObj = $("#lifePolicyTable");
                    tableObj.find("tbody").remove();
                    tableObj.append(tableContent);

                    var strPage = creatChannelPage(pageIndex,6,page.maxPage,"27");
                    var pageDIV = $("#lifePolicyPageDiv");
                    pageDIV[0].innerHTML="";
                    pageDIV.append(strPage);

                }
            });
        }
        //日期格式化
        Date.prototype.format = function(format)
        {
            var o = {
                "M+" : this.getMonth()+1, //month
                "d+" : this.getDate(),    //day
                "h+" : this.getHours(),   //hour
                "m+" : this.getMinutes(), //minute
                "s+" : this.getSeconds(), //second
                "q+" : Math.floor((this.getMonth()+3)/3),  //quarter
                "S" : this.getMilliseconds() //millisecond
            }
            if(/(y+)/.test(format)) format=format.replace(RegExp.$1,
                (this.getFullYear()+"").substr(4 - RegExp.$1.length));
            for(var k in o)if(new RegExp("("+ k +")").test(format))
                format = format.replace(RegExp.$1,
                    RegExp.$1.length==1 ? o[k] :
                        ("00"+ o[k]).substr((""+ o[k]).length));
            return format;
        }

        //默认带出最近一个月的信息
        function defaultDate(){
            var begin=new Date();
            var end=new Date();
            new Date(begin.setMonth((new Date().getMonth()-1)));
            var begintime= begin.format("yyyy-MM-dd");
            var endtime=end.format("yyyy-MM-dd");
            $("#tradeBeginTime").val(begintime);
            $("#tradeEndTime").val(endtime);
        }

        // 校验查询条件
        function checkConditions() {
            var polno= $.trim($("#polno").val());//保单号
            var endorseNo= $.trim($("#endorseNo").val());//批单号
            var tradeBeginTime=  $.trim($("#tradeBeginTime").val());//交易开始日期
            var tradeEndTime=  $.trim($("#tradeEndTime").val());//交易结束日期
            var jsonDate = {
                polno:polno,
                endorseNo: endorseNo,
                tradeBeginTime:tradeBeginTime,
                tradeEndTime:tradeEndTime
            }
            return jsonDate
        }

        // 导出到Excel按钮
        function exportExcel() {
            var queryCondition = "";
            // 查询条件，false：查询条件全部为空，true查询条件不为空
            var flag = false;
            var num = 0;
            if (zfbMap !== {}) {
                $.map(zfbMap, function (value, key) {
                    //遍历map判断上一次的查询条件是否为空，不为空的拼接为参数
                    if (value !== null && value !== '') {
                        if (num === 0) {
                            queryCondition += "?" + key + "=" + value;
                        } else {
                            queryCondition += "&" + key + "=" + value;
                        }
                        flag = true;
                        num++;
                    }
                })
            }
            if (flag === false) {
                $.dialog({
                    type: "warn",
                    content: "查询条件为空，是否全量导出？全量查询将耗费大量时间！<br>请输入查询条件点击查询后再进行导出。",
                    onOk: function () {
                        exportExcelDownload(queryCondition);
                    }
                })
            } else {
                exportExcelDownload(queryCondition);
            }
        }
        // 导出为Excel表格的url
        function exportExcelDownload(queryConditionParam) {
            window.open('<%=basePath%>' + "zfbController/exportRefundInfo" + queryConditionParam);
        }
    </script>
</head>
<body>
<div class="current">
    <table class="current_table_1">
        <tbody>
        <tr class="f2">
            <td><img src="./images/current_1.jpg"></td>
            <td class="current_table_1_td">
                <img src="images/current_1.png">&nbsp;您现在的位置：&nbsp;
                <span style=" color:#136bab; ">支付宝营业厅信息
                        <span style="padding:0 5px; font-weight:bold; line-height:28px;">&gt;</span>批单查询
                      </span>
            </td>
            <td><img src="./images/current_3.jpg"></td>
        </tr>
        </tbody>
    </table>
</div>

<!--查询条件及结果表单 -->
<table border="1" class="table_02" style="height:150px">
    <tr height="50px">
        <td colspan="2" align="center">
            <form method="post" id="downloadlifePolicyFileForm">
                <table border="0" style="margin: 12px auto;">
                    <tr>
                        <td style="border: 0;text-align: right;" nowrap="nowrap">保单号：</td>
                        <td style="border: 0;text-align: left;padding-right: 70px">
                            <input name="policyNo" id="polno" class="input_text" style="width:130px;" size="25"/>
                        </td>
                        <td style="border: 0;text-align: right;" nowrap="nowrap">批单号：</td>
                        <td style="border: 0;text-align: left;padding-right: 70px">
                            <input name="endorseNo" id="endorseNo" class="input_text" style="width:130px;" size="25"/>
                        </td>
                    </tr>
                    <tr>
                        <td style="border: 0;text-align: right;" nowrap="nowrap">交易日期：</td>
                        <td style="border: 0;text-align: left;padding-right: 70px">
                            <input id="tradeBeginTime" name="tradeBeginTime" readonly="readonly" onclick="showCalendar('tradeBeginTime','y-mm-dd');"   class="input_time"/>
                        </td>
                        <td style="border: 0;text-align: right;" nowrap="nowrap">至：</td>
                        <td style="border: 0;text-align: left;padding-right: 70px">
                            <input id="tradeEndTime" name="tradeEndTime" readonly="readonly" onclick="showCalendar('tradeEndTime','y-mm-dd');"  class="input_time"/>
                        </td>
                    </tr>
                    <tr>
                        <td colspan="6" style="border: 0;padding-top: 5px;padding-right: 70px">
                            <input type="button"  class="input_button_1"  value="查询"    onClick="queryLifePolicy()"/>
                            <input type="button"  class="input_button_1"  value="重置"    onClick="resetCriteria()"/>
                        </td>
                    </tr>
                </table>
            </form>
        </td>
    </tr>
    <tr>
        <td>
            <table class="search_table" style="margin: auto;">
                <tr>
                    <td>
                        <input id="exportExcel" type="button" class="input_button_4" value="导出Excel"
                               onclick="exportExcel()"/>
                    </td>

                </tr>
            </table>
        </td>
    </tr>
    <tr>
        <td valign="top">
            <div id="lifePolicyDiv" style="width:98%;margin:5px" >
                <table class="table_02" id="lifePolicyTable">
                    <thead>
                    <tr>
                        <th style="width:18%" nowrap="nowrap">商户订单号</th>
                        <th style="width:18%" nowrap="nowrap">保单号</th>
                        <th style="width:18%" nowrap="nowrap">批单号</th>
                        <th style="width:5%" nowrap="nowrap">实退保费（含税）</th>
                        <th style="width:8%" nowrap="nowrap">退保生效日期</th>
                        <th style="width:15%" nowrap="nowrap">交易日期</th>
                        <th style="width:10%" nowrap="nowrap">保单起期</th>
                        <th style="width:10%" nowrap="nowrap">保单止期</th>
                        <th style="width:9%" nowrap="nowrap">被保险人</th>
                        <th style="width:9%" nowrap="nowrap">生效前/生效后</th>
                    </tr>
                    </thead>
                    <tbody>
                    </tbody>
                </table>
                <div id="lifePolicyPageDiv"  class="page"></div>
            </div>
        </td>
    </tr>
</table>
</body>
</html>
